package com.glory.brepda.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.entity.GoldenSampleTestDataEntity;
import com.glory.brepda.R;
import com.glory.brepda.base.MyApp;
import com.glory.brepda.entity.GoldenSampleTestDataEntity;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralFragmentDialog;
import com.pda.platform.ui.ui_pdaplatform.dialog.FreeUI_GeneralPop;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DialogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_PopUtils;

import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GoldenResultAdapter extends BaseQuickAdapter<GoldenSampleTestDataEntity.DataEntity, BaseViewHolder> {

    Context context;
    ArrayList<String> codeList = new ArrayList<>();
    ArrayList<String> resultList = new ArrayList<>();
    private AlertDialog dialog;
    private String top=null;
    private FreeUI_GeneralPop mCodePop;
    private FreeUI_GeneralPop resultPop;
    private FragmentManager supportFragmentManager;

    public GoldenResultAdapter(@Nullable List<GoldenSampleTestDataEntity.DataEntity> data, Context context, FragmentManager supportFragmentManager) {
        super(R.layout.item_golden_result,data);
        this.context = context;
        this.supportFragmentManager = supportFragmentManager;
        resultList.add("有效");
        resultList.add("无效");
    }

    @Override
    protected void convert(BaseViewHolder helper, GoldenSampleTestDataEntity.DataEntity item) {
        helper.setText(R.id.tvNo,item.getSERIAL_NO());
        helper.setText(R.id.tvTestFLG,item.getTEST_FLG());
        helper.setText(R.id.tvHBIN_NO,item.getHBIN_NO());
        helper.setText(R.id.tvCode,item.getSampleNo());
        helper.setText(R.id.tvResult,item.getDataStatus().equals("1") ? "有效" : "无效");

        StringBuffer sb = new StringBuffer();
        if(!sb.toString().contains(top) && StringUtils.isNotEmpty(top)){
            sb.append(top);
            sb.append("------------\n");
        }
        sb.append(item.getResultInfo().getResultCode() + ',');
        sb.append(item.getResultInfo().getResultInfo() + ';');
        sb.append("\r\n");
        sb.append(item.getResultInfo().getBinNoInfo().getResultCode() + ',');
        sb.append(item.getResultInfo().getBinNoInfo().getResultInfo() + ';');
        sb.append("\r\n");
        sb.append(item.getResultInfo().getBinResultInfo().getResultCode() + ',');
        sb.append(item.getResultInfo().getBinResultInfo().getResultInfo() + ';');
        sb.append("\r\n");
        sb.append(item.getResultInfo().getBinItemInfos().getResultCode() + ',');
        sb.append(item.getResultInfo().getBinItemInfos().getResultInfo() + ';');
        sb.append("\r\n");
        for (GoldenSampleTestDataEntity.BinReturnInfoEntity itemInfo : item.getResultInfo().getBinItemInfos().getItemInfos()) {
            sb.append(itemInfo.getResultCode() + ',');
            sb.append(itemInfo.getResultInfo() + ';');
            sb.append("\r\n");
        }


        TextView tvResultInfo = helper.getView(R.id.tvResultInfo);
        tvResultInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //final EditText check = new EditText(context);
                AlertDialog.Builder builder = new AlertDialog.Builder(context)
                        .setTitle("提示：")
                        .setMessage(sb.toString())
                        //.setIcon(R.drawable.lanjian) //设置图标
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {//在对话框中设置“确定”按钮
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialog.dismiss();
                            }
                        });
                dialog = builder.create();
                dialog.show();
                dialog.setCanceledOnTouchOutside(false);
                dialog.setCancelable(false);
            }
        });

    }

    public void setDataList(String strings) {
        //codeList.addAll(strings);
        top=strings;

    }
}
